package com.ljc.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ljc.service.*;
import com.ljc.shiro.AccountProfile;
import org.apache.shiro.SecurityUtils;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.ServletRequestUtils;

import javax.servlet.http.HttpServletRequest;
import java.security.Security;

/**
 * 抽一些多余的方法
 */
@Controller
public class BaseController {
    @Autowired
    HttpServletRequest httpServletRequest;
    @Autowired
    PostService postService;
    @Autowired
    CommentService commentService;
    @Autowired
    UserService userService;
    @Autowired
    UserMessageService userMessageService;
    @Autowired
    UserCollectionService collectionService;
    @Autowired
    CategoryService categoryService;
    @Autowired
    WsService wsService;
    @Autowired
    SearchService searchService;
    @Autowired
    AmqpTemplate amqpTemplate;
    @Autowired
    ChatService chatService;
    public Page getPage(){
        int pageNum= ServletRequestUtils.getIntParameter(httpServletRequest,"pn",1);
        int pageSize= ServletRequestUtils.getIntParameter(httpServletRequest,"size",2);
        Page page=new Page(pageNum,pageSize);
        return  page;
    }
    public AccountProfile getProfile(){
      return (AccountProfile) SecurityUtils.getSubject().getPrincipal();
    }
    protected Long getProfileId(){
        return  getProfile().getId();
    }

}
